﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Antu.Business
{
    public class ProcessBarClass
    {
        public static void Process(Page xpage, string tag)
        {
            //name=\"LayProcessBar\" by ljt 2007-04-03
            xpage.Response.Write("<div id=\"LayProcessBar\" name=\"LayProcessBar\" style='DISPLAY:none; Z-INDEX:1; LEFT:150px;WIDTH:500px; POSITION:absolute; TOP:250px; HEIGHT:5px; BACKGROUND-COLOR:#eaeaea; layer-background-color:#EAEAEA'>-</div>");
            switch (tag)
            {
                case "1":
                    ProcessBarClass.OnProcess(xpage);
                    break;
                case "2":
                    ProcessBarClass.DownProcess(xpage);
                    break;
            }

        }

        public static void DownProcess(Page xpage)
        {
          
            xpage.Response.Clear();
            xpage.Response.Buffer = true;
            xpage.Response.Write("<script language='javascript'>");
            xpage.Response.Write(" var i;");
            xpage.Response.Write("LayProcessBar.innerText= '';");

            xpage.Response.Write("function ClearWait()");
            xpage.Response.Write("{");
            xpage.Response.Write("	LayProcessBar.style.display = 'none';");
            xpage.Response.Write("	window.clearInterval();");
            xpage.Response.Write("}");
            xpage.Response.Write(" ClearWait();</script>");
            xpage.Response.Flush();

        }

        public static void OnProcess(Page xpage)
        {
            xpage.Response.Write("<script language='javascript'>");
            xpage.Response.Write(" var i;");
            xpage.Response.Write("LayProcessBar.innerText= '';");
            xpage.Response.Write("function StartShowWait()");
            xpage.Response.Write("{");
            xpage.Response.Write("	i = 0;");
            xpage.Response.Write("	LayProcessBar.style.display = 'inline';");
            xpage.Response.Write("	window.setInterval('ShowWait()',200);");
            xpage.Response.Write("}");
            xpage.Response.Write("function ShowWait()");
            xpage.Response.Write("{");
            xpage.Response.Write("	if (i >= 50)");
            xpage.Response.Write("	{");
            xpage.Response.Write("		LayProcessBar.innerText='';");
            xpage.Response.Write("		i = 1;");
            xpage.Response.Write("	}");
            xpage.Response.Write("	oDiv = document.createElement('DIV');");
            xpage.Response.Write("	oDiv.style.position = 'relative';");
            xpage.Response.Write("	oDiv.style.marginLeft = '1px';");
            xpage.Response.Write("	oDiv.style.display = 'inline';");
            xpage.Response.Write("	oDiv.style.backgroundColor = '#35D538';");
            xpage.Response.Write("	oDiv.style.height = '100%';");
            xpage.Response.Write("	oDiv.style.width = '9';");
            xpage.Response.Write("	oDiv.style.height = '5';");
            xpage.Response.Write("	LayProcessBar.appendChild(oDiv);");
            xpage.Response.Write("	i++;");
            xpage.Response.Write("}");
            xpage.Response.Write("function ClearWait()");
            xpage.Response.Write("{");
            xpage.Response.Write("	LayProcessBar.style.display = 'none';");
            xpage.Response.Write("	window.clearInterval();");
            xpage.Response.Write("}");
            xpage.Response.Write("StartShowWait();</script>");
            xpage.Response.Buffer = true;
            xpage.Response.Flush();
          
        }
    }
}
